import { getSalesData, getPvData, getPaymentData, getUserActiveData, getOrderChartData, getOrderGeneral  } from '../services/api';

export default {
  namespace: 'orderAnalysis',

  state: {
    loading: false,
    orderData : [],
    baseData : {},
  },

  effects: {
    *fetch(_, { call, put }) {
      const response = yield call(getOrderGeneral);
      if(response){
        yield put({
          type: 'save',
          payload: {
            baseData: response,
          },
        });
      }
    },
    *fetchOrderData({ payload }, { call, put }) {
      const response = yield call(getOrderChartData, payload);
      if(response){
        yield put({
          type: 'save',
          payload: {
            orderData : response
          },
        });
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    clear() {
      return {
        orderData : [],
        baseData : {},
      };
    },
  },
};
